package  demo6;

import java.util.Random;

public class LogicPuzzle {
    public BornRatio createBornRatio(){
        return new BornRatio();
    }
    enum SEX{
        BOY,GIRL
    }
    /**
     *     // get the number of girl ,and the boy ,
     *                 // when test many times,
     */
    public class BornRatio{
        private Random random = new Random();
        // get the ratio
        public void multiBorn(int times){
            // 0-99 100 times
            int girlSum=0,boySum=0;
            int i=times-1;
            while ((i--)!=0){
                int[] born = born();
                boySum+=born[0];
                girlSum+=born[1];
            }
            System.out.println("boySum:"+boySum+" , girlSum:"+girlSum);
            double v = boySum / (double) (boySum + girlSum);
            System.out.println("ratio: "+v);
        }

        public int[] born(){
            // 0=>boy,1=>girl
            int girl = 0,boy=0;
            int i = random.nextInt(2);
            if(i==1){
                girl++;
            }
            // stop loop after she born the girl
            while(i==0){
                boy++;
                i = random.nextInt(2);
                if(i==1){
                  girl++;
                }
            }
            return new int[]{boy,girl};
        }
    }
}
